#include "testdatamapping.h"

#include <QDebug>

#include "ui_testdatamapping.h"

TestDataMapping::TestDataMapping(QWidget *parent) : QWidget(parent), ui(new Ui::TestDataMapping) {
    ui->setupUi(this);

    config_ = {{"192.168.1.1", 8080, false}, {true, 2}, 3.14f};
    setBindings();
    mapper_.loadToWidgets();
}

TestDataMapping::~TestDataMapping() { delete ui; }

void TestDataMapping::setBindings() {
    mapper_.bind(ui->ipLineEdit, "network.ip");
    mapper_.bind(ui->portSpinBox, "network.port");
    mapper_.bind(ui->dhcpCheckBox, "network.dhcp");
    mapper_.bind(ui->debugCheckBox, "settings.debugMode");
    mapper_.bind(ui->logLevelSpinBox, "settings.logLevel");
    mapper_.bind(ui->timeoutSpinBox, "timeout");
}

void TestDataMapping::dumpConfig() {
    qDebug() << "Current Config:\n"
             << "Ip: " << config_.network.ip << '\n'
             << "port: " << config_.network.port << '\n'
             << "dhcp: " << config_.network.dhcp << '\n'
             << "debug: " << config_.settings.debugMode << '\n'
             << "log level: " << config_.settings.logLevel << '\n'
             << "timeout: " << config_.timeout;
}

void TestDataMapping::on_saveBtn_clicked() { dumpConfig(); }
